#!/usr/bin/python
# -*- coding: UTF-8 -*-

import tkinter
from tkinter import filedialog
from PIL import Image, ImageTk
from ss import ss

class MainWindow():
  def __init__(self, title):
    self.window = tkinter.Tk()
    self.title = title

    self.render();
    print('窗口初始化完成')
    self.window.mainloop()

  def render(self):
    self.window.title(self.title)
    self.window.geometry('1068x681+10+10')
    self.renderBtn()
    self.renderImg()

  def renderBtn(self):
    Btn = tkinter.Button(
      self.window, 
      text='选择图片', 
      command=self.handlleOnSelectImage,
      fg="red",
      activeforeground="red"
    )
    Btn2 = tkinter.Button(
      self.window, 
      text='生成', 
      command=self.generate,
      fg="red",
      activeforeground="red"
    )
    Btn.pack()
    Btn2.pack()
    pass

  def renderImg(self):
    self.canvas = tkinter.Canvas(
      self.window,
    )
    pass


  def handlleOnSelectImage(self):
    print('选择图片')
    File = filedialog.askopenfilename(parent=self.window, initialdir="C:/",title='Choose an image.')
    filename = ImageTk.PhotoImage(Image.open(File))

    self.filePath = File
   
    self.canvas.image = filename  # <--- keep reference of your image
    self.canvas.create_image(0,0,anchor='nw',image=filename)
    self.canvas.pack()
  
  def generate(self):
    print('生成')
    ss(self.filePath)
    pass
